package com.googlecode.svnj.reports;

import java.util.HashMap;
import java.util.Map;

/** analog of svn_depth_t, see svn_types.h */
public enum Depth {

    UNKNOWN(-2),
    EXCLUDE(-1),
    EMPTY(0),
    FILES(1),
    IMMEDIATES(2),
    INFINITY(3);
    
    private static final Map<String,Depth> strings =
        new HashMap<String,Depth>(6);
    static {
        for (Depth d: Depth.class.getEnumConstants()) {
            strings.put(d.toString(), d);
        }
    }
    private final int value;
    private Depth(int v) {
        value = v;
    }

    /* compatible with svn_depth_t enum */
    public int getValue() { return value; }
    
    public static Depth fromString(String s) {
        Depth ret = strings.get(s);
        if (ret == null) {
            throw new IllegalArgumentException(
                    "Invalid depth: '" + s + "'"
                    );
        }
        return ret;
    }
    
    @Override
    public String toString() {
        switch (this) {
            case UNKNOWN:
                return "unknown";
            case EXCLUDE:
                return "exclude";
            case EMPTY:
                return "empty";
            case FILES:
                return "files";
            case IMMEDIATES:
                return "immediates";
            case INFINITY:
                return "infinity";
            default:
                throw new RuntimeException(
                        "invalid depth: " + this.value
                        );
        }
    }
    
}
